<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<body>
<a href="solvechangefile.jsp">返回</a>
<a href="index1.jsp">主页</a><br>
<table border="1" width="100%" >
  <tr>
    <th width="40">序号</th>
    <th width="40">学号</th>
    <th width="40">姓名</th>
    <th width="40">学籍状态</th>
    <th width="40">更改状态时间</th>
  </tr>
  <%
    request.setCharacterEncoding("utf-8");
    String id = request.getParameter("id");
    String status = request.getParameter("status");
    String year = request.getParameter("year");
    String month = request.getParameter("month");
    String day = request.getParameter("day");
    String Date =year+"-"+month+"-"+day;
    //加载驱动
    Class.forName("com.mysql.cj.jdbc.Driver");
    //连接数据库
    Connection DataConnection = java.sql.DriverManager.getConnection("jdbc:mysql://127.0.0.1:3307/file?useSSL=FALSE&serverTimezone=UTC"
            , "root", "123456");
    Statement DataStatement = DataConnection.createStatement();
    ResultSet UserIsExistResult = DataStatement.executeQuery("select user_id from student" +
            " where user_id = '" + id+ "'");
    //如果存在
    if (UserIsExistResult.next()) {
      DataStatement.executeUpdate(
              "update dangan set Enrollment_Status='" + status + "',Change_ES_Time='" + Date + "'where " +
                      "user_id='" + id + "'");
      ResultSet rs = DataStatement.executeQuery("select A.user_id,user_name,Enrollment_Status,Change_ES_Time from student A,dangan B " +
              "where A.user_id=B.user_id and A.user_id='"+id+"'");
      int count = 1;
      while (rs.next()) {
        out.print("<tr>");
        out.print("<td>" + (count++) + "</td>");
        out.print("<td>" + rs.getString("user_id") + "</td>");
        out.print("<td>" + rs.getString("user_name") + "</td>");
        out.print("<td>" + rs.getString("Enrollment_Status") + "</td>");
        out.print("<td>" + rs.getString("Change_ES_Time") + "</td>");
        out.print("</tr>");
      }
    }
    else {
      out.print("<tr>");
      out.print("<h1>该学生学号不存在！<h1>");
      out.print("</tr>");
    }
  %>
</table>
<%@include file="footer.jsp" %>
</body>
</html>
